package com.heima.media.controller;

import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.WmSensitiveDto;
import com.heima.media.entity.WmSensitive;
import io.swagger.annotations.Api;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.heima.media.service.IWmSensitiveService;

import java.util.Date;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 敏感词信息表 前端控制器
 * </p>
 *
 * @author mcm
 * @since 2022-06-21
 */
@RestController
@RequestMapping("/api/v1/sensitive")
@Api(tags = "敏感词信息表接口")
public class WmSensitiveController{

    @Autowired
    private IWmSensitiveService wmSensitiveService;


    /**
     * 敏感词列表查询
     * @param wmSensitiveDto
     * @return
     */
    @PostMapping("/list")
    public ResponseResult list(@RequestBody WmSensitiveDto wmSensitiveDto){
        return wmSensitiveService.listBy(wmSensitiveDto);
        }

    /**
     * 添加敏感词
     * @param wmSensitive
     * @return
     */
    @PostMapping
    public ResponseResult save(@RequestBody WmSensitive wmSensitive){
        wmSensitive.setCreatedTime(new Date());
        wmSensitiveService.save(wmSensitive);
        return ResponseResult.okResult();
    }

    /**
     * 敏感词修改
     * @param sensitiveDto
     * @return
     */
    @PutMapping
    public ResponseResult updateByName(@RequestBody WmSensitive sensitiveDto){
        wmSensitiveService.updateById(sensitiveDto);
        return ResponseResult.okResult();
    }

    @DeleteMapping("/{id}")
    public ResponseResult delete(@PathVariable(value = "id")Integer id){
        wmSensitiveService.removeById(id);
        return ResponseResult.okResult();
    }
}
